Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tree-node-cli

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-node-cli

Lists the contents of directories in a tree-like format, similar to the Linux tree command.

  • 1.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.1K
decreased by-79.93%
Maintainers
2
Weekly downloads
 
Created
Source

tree-node-cli

Lists the contents of directories in a tree-like format, similar to the Linux tree command. Both CLI and Node APIs are provided.

Tree is a recursive directory listing program that produces a depth indented listing of files. When a directory argument is given, tree lists all the files and/or directories found in the given directory.

Note: Symlinks are not followed.

Installation

$ npm install tree-node-cli
# or globally
$ npm install -g tree-node-cli

Example

$ tree -L 2 -I "node_modules"
tree-node-cli
├── LICENSE
├── README.md
├── __tests__
│   ├── __fixtures__
│   ├── __snapshots__
│   ├── fixtures
│   └── tree.test.js
├── bin
│   └── tree
├── jest.config.js
├── package.json
├── tree.js
└── yarn.lock

CLI

$ tree [options] [path/to/dir]

Note: Use the command treee on Windows and Linux to avoid conflicts with built-in tree command.

The following options are available:

$ tree -h

  Usage: tree [options]

  Options:

    -V, --version             output the version number
    -a, --all-files           All files, include hidden files, are printed.
    --dirs-first              List directories before files.
    -d, --dirs-only           List directories only.
    -s, --sizes               Show filesizes.
    -I, --exclude [patterns]  Exclude files that match the pattern. | separates alternate patterns. Wrap your entire pattern in double quotes. E.g. `"node_modules|coverage".
    -L, --max-depth <n>       Max display depth of the directory tree.
    -r, --reverse             Sort the output in reverse alphabetic order.
    -F, --trailing-slash      Append a '/' for directories.
    -S, --line-ascii          Turn on ASCII line graphics.
    -h, --help                output usage information

API

const tree = require('tree-node-cli');
const string = tree('path/to/dir', options);

options is a configuration object with the following fields:

FieldDefaultTypeDescription
allFilesfalseBooleanAll files are printed. By default, tree does not print hidden files (those beginning with a dot).
dirsFirstfalseBooleanList directories before files.
dirsOnlyfalseBooleanList directories only.
sizesfalseBooleanShow filesizes as well.
exclude[]ArrayAn array of regex to test each filename against. Matching files will be excluded and matching directories will not be traversed into.
maxDepthNumber.POSITIVE_INFINITYNumberMax display depth of the directory tree.
reversefalseBooleanSort the output in reverse alphabetic order.
trailingSlashfalseBooleanAppends a trailing slash behind directories.
lineAsciifalseBooleanTurn on ASCII line graphics.
const string = tree('path/to/dir', {
  allFiles: true,
  exclude: [/node_modules/, /lcov/],
  maxDepth: 4,
});

console.log(string);

License

MIT

Keywords

FAQs

Package last updated on 26 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc